package com.ruoyi.edit.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Objects;

import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.edit.utils.UuidUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.edit.mapper.VendorCourseRelPackagev2Mapper;
import com.ruoyi.edit.domain.VendorCourseRelPackagev2;
import com.ruoyi.edit.service.IVendorCourseRelPackagev2Service;
import com.ruoyi.common.core.text.Convert;

/**
 * 课程教保指引关联Service业务层处理
 * 
 * @author qiufeng
 * @date 2022-12-15
 */
@Service
public class VendorCourseRelPackagev2ServiceImpl implements IVendorCourseRelPackagev2Service 
{
    @Autowired
    private VendorCourseRelPackagev2Mapper vendorCourseRelPackagev2Mapper;

    /**
     * 查询课程教保指引关联
     * 
     * @param id 课程教保指引关联主键
     * @return 课程教保指引关联
     */
    @Override
    public VendorCourseRelPackagev2 selectVendorCourseRelPackagev2ById(String id)
    {
        return vendorCourseRelPackagev2Mapper.selectVendorCourseRelPackagev2ById(id);
    }

    /**
     * 查询课程教保指引关联列表
     * 
     * @param vendorCourseRelPackagev2 课程教保指引关联
     * @return 课程教保指引关联
     */
    @Override
    public List<VendorCourseRelPackagev2> selectVendorCourseRelPackagev2List(VendorCourseRelPackagev2 vendorCourseRelPackagev2)
    {
        if (Objects.nonNull(vendorCourseRelPackagev2.getAge()) && !StringUtils.equals("",vendorCourseRelPackagev2.getAge())) {
            String[] ages = vendorCourseRelPackagev2.getAge().split("-");
            if (ages.length>1){
                Integer ageLow = Integer.valueOf(ages[0]);
                Integer ageHigh = Integer.valueOf(ages[1]);
                vendorCourseRelPackagev2.setAgeLow(ageLow);
                vendorCourseRelPackagev2.setAgeHigh(ageHigh);
            }else {
                vendorCourseRelPackagev2.setAgeLow(Integer.valueOf(vendorCourseRelPackagev2.getAge()));
                vendorCourseRelPackagev2.setAgeHigh(Integer.valueOf(vendorCourseRelPackagev2.getAge()));
                vendorCourseRelPackagev2.setAge(null);
            }
        }
        return vendorCourseRelPackagev2Mapper.selectVendorCourseRelPackagev2List(vendorCourseRelPackagev2);
    }

    /**
     * 新增课程教保指引关联
     * 
     * @param vendorCourseRelPackagev2 课程教保指引关联
     * @return 结果
     */
    @Override
    public int insertVendorCourseRelPackagev2(VendorCourseRelPackagev2 vendorCourseRelPackagev2)
    {
        vendorCourseRelPackagev2.setId(UuidUtil.getUuid());
        vendorCourseRelPackagev2.setDeleted(0);
        vendorCourseRelPackagev2.setCreated(new Date());
        vendorCourseRelPackagev2.setCreateBy(ShiroUtils.getLoginName());
        vendorCourseRelPackagev2.setCreatedName(ShiroUtils.getName());
        return vendorCourseRelPackagev2Mapper.insertVendorCourseRelPackagev2(vendorCourseRelPackagev2);
    }

    /**
     * 修改课程教保指引关联
     * 
     * @param vendorCourseRelPackagev2 课程教保指引关联
     * @return 结果
     */
    @Override
    public int updateVendorCourseRelPackagev2(VendorCourseRelPackagev2 vendorCourseRelPackagev2)
    {
        vendorCourseRelPackagev2.setCreateBy(ShiroUtils.getLoginName());
        vendorCourseRelPackagev2.setCreatedName(ShiroUtils.getName());
        return vendorCourseRelPackagev2Mapper.updateVendorCourseRelPackagev2(vendorCourseRelPackagev2);
    }

    /**
     * 批量删除课程教保指引关联
     * 
     * @param ids 需要删除的课程教保指引关联主键
     * @return 结果
     */
    @Override
    public int deleteVendorCourseRelPackagev2ByIds(String ids)
    {
        return vendorCourseRelPackagev2Mapper.deleteVendorCourseRelPackagev2ByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除课程教保指引关联信息
     * 
     * @param id 课程教保指引关联主键
     * @return 结果
     */
    @Override
    public int deleteVendorCourseRelPackagev2ById(String id)
    {
        return vendorCourseRelPackagev2Mapper.deleteVendorCourseRelPackagev2ById(id);
    }
}
